package com.csdj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.mapper.SyEmpMapper;
import com.csdj.pojo.BeHistory;
import com.csdj.pojo.SyEmp;
import com.csdj.service.BeHistoryService;
import com.csdj.mapper.BeHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 叶涵
 * @description 针对表【be_history】的数据库操作Service实现
 * @createDate 2023-08-24 15:13:39
 */
@Service
public class BeHistoryServiceImpl extends ServiceImpl<BeHistoryMapper, BeHistory>
        implements BeHistoryService {
    @Autowired
    private BeHistoryMapper beHistoryMapper;
    @Autowired
    private SyEmpMapper syEmpMapper;

    @Override
    public List<BeHistory> getAll(String oid) {
        LambdaQueryWrapper<BeHistory> lq = new LambdaQueryWrapper<>();
        lq.eq(BeHistory::getOrderNo,oid);
        List<BeHistory> list = beHistoryMapper.selectList(lq);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setSyEmp(syEmpMapper.selectById(list.get(i).getEmpID()));
        }
        return list;
    }

    @Override
    public void getRemovePojo(String orderNo) {
        LambdaQueryWrapper<BeHistory> l=new LambdaQueryWrapper<>();
        l.orderByDesc(BeHistory::getDatee);
        l.eq(BeHistory::getOrderNo,orderNo);
        List<BeHistory> li = beHistoryMapper.selectList(l);
        beHistoryMapper.deleteById(li.get(0));
    }
}




